#version 440 core

#define LOC_SIZE_X 16
#define LOC_SIZE_Y 16

#define GRID_SIZE_X 64
#define GRID_SIZE_Y 64

layout(local_size_x=LOC_SIZE_X, local_size_y=LOC_SIZE_Y) in;

layout(binding=0, r32ui) uniform readonly uimage2D levelSetStateImage;
layout(binding=1, r32f) uniform readonly image2D levelSetImageSrc;
layout(binding=2, r32f) uniform writeonly image2D levelSetImageDst;

void main(void)
{
	ivec2 gid = ivec2(gl_GlobalInvocationID.xy);
	bvec2 cond = lessThan(gid, ivec2(GRID_SIZE_X+1, GRID_SIZE_Y+1));
	if (cond.x && cond.y)
	{
		if (imageLoad(levelSetStateImage, gid).x == 0)
		{
			imageStore(levelSetImageDst, gid, vec4(imageLoad(levelSetImageSrc, gid).x, 0.0, 0.0, 1.0));
		}
	}
}